package com.itheima.ydd.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.itheima.ydd.common.JacksonObjectMapper;
import com.itheima.ydd.dto.SysMenuDto;
import com.itheima.ydd.entity.Result;
import com.itheima.ydd.entity.SysMenu;
import com.itheima.ydd.service.SysMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@Slf4j
@RequestMapping("/sys_menu")
public class SysMenuController {


    @Autowired
    private SysMenuService sysMenuService;


    //新增菜单
    @PostMapping("/add")
    public Result addSysMenu(@RequestBody Map<String, Object> sysMenu) {
        return sysMenuService.addSysMenu(sysMenu);
    }


    //菜单修改
    @PostMapping("/update")
    public Result updateSysMenu(@RequestBody Map<String,Object> map) {
        String jsonString = JSON.toJSONString(map);
        SysMenu sysMenu = JSON.parseObject(jsonString,SysMenu.class);
        boolean b = sysMenuService.updateById(sysMenu);
        System.out.println(b);
        return new Result(0,"");
    }


    //查询所有
    @GetMapping("/allData")
    public Result findAll() {
        List<SysMenuDto> list =  sysMenuService.allData();
        return new Result(0,"",list);
    }

    //菜单详情
    @GetMapping("/rowInfo")
    public Result details(Integer id) {
        return new Result(0, "", sysMenuService.getById(id));
    }


    //根据id删除菜单
    @GetMapping("/del")
    public Result deleteById(String id) {

        return null;
    }


}



